package com.qf.flash.mvp.presenter;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;

import com.qf.flash.http.HttpManager;
import com.qf.flash.http.response.PlayTypeBean;
import com.qf.flash.model.StrategyBean;
import com.qf.flash.mvp.contract.StrategyContract;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseResponse;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

import java.util.List;

public class StrategyPresenter extends BasePresenter<StrategyContract.View> implements StrategyContract.Presenter {
    private MutableLiveData<List<PlayTypeBean>> liveData = new MutableLiveData<>();

    @Override
    public void getMethodList(String typeId, String isTop, int pageNo, int pageSize) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .GET_METHOD_LIST(typeId, isTop, pageNo, pageSize)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<List<StrategyBean>>>(mRootView) {

                    @Override
                    public void onSuccess(BaseResponse<List<StrategyBean>> listBaseResponse) {
                        mRootView.setStrategyListData(listBaseResponse.getData(), listBaseResponse.getTotalPage());
                    }
                }));
    }

    public void getPlayType() {
        addSubscription(HttpManager.getInstance().getGsonHttpApi().PLAY_TYPES()
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribe(playTypeBeans -> {
                            liveData.postValue(playTypeBeans);
                        }
                ));
    }

    public LiveData<List<PlayTypeBean>> getTypeLiveData() {
        return liveData;
    }

}
